/****************************************************************************
 *
 *  3DSERR.H
 *
 *  (C) Copyright 1997 by Autodesk, Inc.
 *
 *  This program is copyrighted by Autodesk, Inc. and is licensed to you under
 *  the following conditions.  You may not distribute or publish the source
 *  code of this program in any form.  You may incorporate this code in object
 *  form in derivative works provided such derivative works are (i.) are de-
 *  signed and intended to work solely with Autodesk, Inc. products, and (ii.)
 *  contain Autodesk's copyright notice "(C) Copyright 1995 by Autodesk, Inc."
 *
 *  AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  AUTODESK SPE-
 *  CIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
 *  A PARTICULAR USE.  AUTODESK, INC.  DOES NOT WARRANT THAT THE OPERATION OF
 *  THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.
 *
 ***************************************************************************/

#ifndef ERR_3DS_H
#define ERR_3DS_H

#include <stdio.h>
#include "3DSTYPE.H"
#include "3DSPRIM.H"

/* Public Typedefs */

/* Error codes generated by toolkit */
typedef enum
{
   NO_FTK_ERRORS = 0, /* No errors are pending */
   ERR_NO_MEM, /* Not enough memory to complete operation */
   ERR_INVALID_ARG, /* The argument passed to the function invalid.  Usually */
		    /* caused by a NULL pointer or an out of range numeric */
		    /* argument. */
   ERR_INVALID_DATA, /* The structure passed as an argument to the function has */
                     /* invalid or out of range data in its fields. */
   ERR_INVALID_CHUNK, /* An invalid chunk structure was encountered while reading */
		      /* the database. Usually caused by a corrupt database or */
		      /* file */
   ERR_INVALID_DATABASE, /* The database passed as an argument has not be created */
			 /* yet. */
   ERR_WRONG_DATABASE, /* The database passed as an argument is the wrong kind of */
		       /* database for this function. */
   ERR_UNFOUND_CHUNK, /* The database is missing important file chunks needed to */
		      /* fill out the requested structure.  Usually caused by a */
		      /* corrupt database or file */
   ERR_WRONG_OBJECT, /* The name passed to the functions exists, but is not the */
		     /* type of object asked for.  For example, asking for a mesh */
		     /* object with the GetCameraByName3ds function. */
   ERR_NO_SUCH_FILE, /* The filename passed as an argument for reading does not exist */
   ERR_INIT_FAILED,  /* Failed to initialize structure passed as an argument */
   ERR_OPENING_FILE, /* Could not open requested file */
   ERR_CLOSING_FILE, /* Could not close requested file */
   ERR_READING_FILE, /* Error occured while reading file */
   ERR_CREATING_DATABASE, /* Error occured while creating database */
   ERR_READING_DATABASE, /* Error occured while reading database */
   ERR_WRITING_DATABASE, /* Error occured while writing database */
   ERR_WRITING_FILE, /* Error occured while writing file */
   ERR_STRING_TOO_LONG, /* String encountered in file, structure, or as an */
			/* argument was longer than expected.  Possibly caused by */
			/* an uninitialed pointer, corrupt file or database */
   ERR_TOO_MANY_FILES, /* The toolkit has reached its maximum open file limit of */
		       /* 252 files. */
   ERR_GET_FAIL, /* Failed to get new data from database */
   ERR_PUT_FAIL, /* Failed to add new data to the database */
   N_ERRORS
}errorid3ds;

typedef struct {
  errorid3ds  id;
  const char3ds *desc;
} ErrRec3ds;

/* End Public */

/* Public Consts */
/* Last toolkit error */
extern byte3ds ftkerr3ds; /* True3ds if error is pending */
extern byte3ds ignoreftkerr3ds; /* True3ds if errors are being ignored by toolkit */
/* End Public */

/* Private Prototypes */
void PushErrList3ds(errorid3ds id);
const char3ds *ErrCodeToString3ds(errorid3ds err);
/* End Private */

/* Public Prototypes */
void DumpErrList3ds(FILE *outfile);
void ClearErrList3ds();
const ErrRec3ds *ReturnErrorList3ds();

/* End Public */

/* Public Defines */
/*------------------------------------
  Error reporting and testing macros
  ----------------------------------*/

/* Pending error flag values for ftkerr3ds global */
#define FTK_ERROR True3ds
#define FTK_NO_ERROR False3ds

/*--- If ftkerr3ds shows that an error has occured, return */
#define ON_ERROR_RETURN {if(ftkerr3ds && !ignoreftkerr3ds) return;}
#define ON_ERROR_RETURNR(rval) {if(ftkerr3ds && !ignoreftkerr3ds) return rval;}

/*--- If ftkerr3ds shows that an error has occured, push error and return */
#define ADD_ERROR_RETURN(id) {if(ftkerr3ds){PushErrList3ds(id); if (!ignoreftkerr3ds) return;}}
#define ADD_ERROR_RETURNR(id, rval) {if(ftkerr3ds){PushErrList3ds(id); if (!ignoreftkerr3ds) return rval;}}

/*--- If ftkerr3ds shows that an error has occured, push error */
#define ADD_ERROR(id) {if (ftkerr3ds){PushErrList3ds(id);}}

/*--- Reset the the error flag */
#define CLEAR_ERROR {if (ftkerr3ds){ClearErrList3ds();}}

/*--- Simply set the error state: Good if you need to clean-up before returning  */
#define SET_ERROR {ftkerr3ds=True3ds;}

/*--- Set error state, push an error ID and return */
#define SET_ERROR_RETURN(id) {PushErrList3ds(id); if (!ignoreftkerr3ds) return;}
#define SET_ERROR_RETURNR(id, rval) {PushErrList3ds(id); if (!ignoreftkerr3ds) return rval;}

/* Prints errors and exits application */
#define PRINT_ERRORS_EXIT(file) {if(ftkerr3ds){DumpErrList3ds(file); if (!ignoreftkerr3ds) exit(-1);}}
/* End Public */
#endif /* ERR_3DS */
